package sctu.edu.java.year2016.team02.huangguojing.day20160605.Chapter12_3;

/**
 * Created by Eoly on 2016/6/5.
 * 编写程序，使用字符输入、输出流读取文件，将一段文字加密后存入文件，然后再读取，并将加密前与加密后的文件输出。
 */

import java.io.File;
import java.io.FileWriter;

class FileOperate {
    String Path;
    String Name;
    File file;

    public FileOperate(File file) {
        this.file = file;
    }

    public FileOperate(String Path) {
        this.Path = Path;
        file = new File(Path);
        if (!file.exists()) {
            try {
                file.createNewFile();
                System.out.println("File is Created.");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    FileOperate(String Path, String Name) {
        this.Name = Name;
        this.Path = Path;
        file = new File(Path, Name);
        if (!file.exists()) {
            try {
                file.createNewFile();
                System.out.println("File is Created.");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    boolean outPut(String words, boolean isRecreat) {
        try {
            FileWriter writer = new FileWriter(file, isRecreat);
            writer.write(words);
            writer.close();
            System.out.println("Writing successful!");
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
